package com.fxkj.cloud.drms.application;

import com.fxkj.cloud.dbs.common.constants.DeviceStatusEnum;
import com.fxkj.cloud.dbs.common.model.aggregation.IntervalType;
import com.fxkj.cloud.dbs.common.model.command.CommandSet;
import com.fxkj.cloud.dbs.common.model.linkage.DeviceAttributeKeyValue;
import com.fxkj.cloud.dbs.common.model.linkage.KvDTO;
import com.fxkj.cloud.drms.application.model.dto.TsQueryDTO;
import com.fxkj.cloud.drms.application.model.vo.BatchTskvView;
import com.fxkj.cloud.drms.application.model.vo.DeviceEnergyModelView;
import com.fxkj.cloud.drms.application.model.vo.ProductEnergyStatisticsModelView;
import com.fxkj.cloud.drms.application.model.vo.TskvView;
import com.fxkj.cloud.dbs.common.model.kv.TsKvEntry;
import com.fxkj.cloud.drms.domain.device.repository.ProductDeviceLightStatistics;
import com.fxkj.cloud.drms.domain.device.repository.ProductDeviceStatusChangeHistory;
import com.fxkj.cloud.drms.domain.device.repository.ProductStatusStatistics;
import com.google.common.util.concurrent.ListenableFuture;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * <p>description: </p>
 * @author ww
 * @date 2025/3/18 13:45
 */
public interface DeviceApplicationService {
    /**
     * 创建设备
     * @param organizationId 组织id
     * @param productId 产品id
     * @param deviceId 设备id
     */
    void createDevice(UUID organizationId, UUID productId, UUID deviceId);

    /**
     * 保存设备数据
     * @param deviceSerialNo 设备序列号
     * @param tsKvEntries 数据
     * @return 保存条数
     */
    ListenableFuture<Integer> saveDeviceData(String deviceSerialNo, List<TsKvEntry> tsKvEntries);

    /**
     * 设备状态变更
     * @param deviceSerialNo
     * @param status
     */
    void deviceStatusChange(String deviceSerialNo, DeviceStatusEnum status);

    /**
     * 获取设备最新数据
     * @param deviceId
     * @return
     */
    ListenableFuture<List<TsKvEntry>> getDeviceLatestTskv(UUID deviceId, Set<String> attributeKeys);

    /**
     * 获取设备最新属性数据
     * @param deviceId
     * @return
     */
    ListenableFuture<List<DeviceAttributeKeyValue>> getDeviceLatestAttributeTskv(UUID deviceId, Set<String> attributeKeys);

    /**
     * 获取设备历史数据
     * @param deviceId
     * @param attributeKeys
     * @param startTime
     * @param endTime
     * @param limit
     * @return
     */
    ListenableFuture<List<TskvView>> getDeviceHistoryTskv(UUID deviceId, Set<String> attributeKeys, long startTime, long endTime, Integer limit);

    /**
     * 设备控制计划下发回应
     * @param requestId
     * @param deviceSerialNo
     */
    void deviceControlPlanCallback(UUID requestId, String deviceSerialNo);

    /**
     * 设备属性设置
     *
     * @param deviceId
     * @param kvSettings
     * @param username
     */
    void deviceKeySet(UUID deviceId, List<KvDTO> kvSettings, String username);

    /**
     * 设备属性设置
     *
     * @param deviceIds
     * @param kvSettings
     * @param username
     */
    void deviceKeySetBatch(List<UUID> deviceIds, List<KvDTO> kvSettings, String username);


    /**
     * 设备命令下发
     *
     * @param commandSet
     * @param username
     */
    void commandKvSet(CommandSet commandSet, String username);

    /**
     * 获取产品状态统计
     *
     * @param organizationId
     * @param productModelId
     * @param productId
     * @param selectTime
     * @return
     */
    ListenableFuture<ProductStatusStatistics> getProductModelStatusStatistics(UUID organizationId, UUID productModelId, UUID productId, Long selectTime);

    /**
     * 获取产品下设备状态变更历史
     *
     * @param organizationId
     * @param productModelId
     * @param productId
     * @param deviceId
     * @param startTime
     * @param endTime
     * @param intervalValue
     * @param intervalTypeEnum
     * @return
     */
    ListenableFuture<ProductDeviceStatusChangeHistory> getProductDeviceStatusChangeHistory(UUID organizationId, UUID productModelId, UUID productId, UUID deviceId, Long startTime, Long endTime, Integer intervalValue, IntervalType intervalTypeEnum);

    /**
     * 获取产品亮灯曲线
     *
     * @param organizationId
     * @param productModelId
     * @param productId
     * @return
     */
    ListenableFuture<List<ProductDeviceLightStatistics>> getProductModelLightStatistics(UUID organizationId, UUID productModelId, UUID productId, Long startTime, Long endTime);

    /**
     * 获取设备历史聚合数据
     * @param tsQueryDTO
     * @return
     */
    ListenableFuture<List<BatchTskvView>> tsQuery(TsQueryDTO tsQueryDTO);


    /**
     * 获取产品能耗统计
     * @param productModelId
     * @param productId
     * @param organizationId
     * @return
     */
    ListenableFuture<ProductEnergyStatisticsModelView> productModelEnergyStatistics(UUID productModelId, UUID productId, UUID organizationId);

}
